from django.template import RequestContext
from django.shortcuts import render_to_response
from django.conf import settings

from pacs.models import Contest
from ham.views import show_page


def show_contest(request,contest_id,page='1'):
	page = int(page)-1
	tasksOnPage = 3

	c = RequestContext(request)
	if page > 0:
		c['prev'] = page 
	contest = Contest.objects.get(id=int(contest_id))
	tasks = contest.tasks.all()[page*tasksOnPage:(page+1)*tasksOnPage+1]
	if len(tasks) > tasksOnPage:
		c['next'] = page + 2
		tasks = tasks[:len(tasks)-1]
	c['contest'] = contest
	c['tasks'] = tasks
	return render_to_response('pacs/show_contest.xhtml',c)

def list_contests(request,page='0'):
	return show_page(request,int(page),Contest.objects.all(),'pacs/list_contests.xhtml',3)

def select_contest(request):
	return render_to_response('pacs/select_contest.xhtml',RequestContext(request))
